//用于扫描消费组件堆栈
const ScanConsumeStack = []
/**
 *
 * @param {*} vueComponent 扫描消费组件
 * @param {*} priority 消费优先级
 */
function addScanConsume(vueComponent, priority) {
    console.log()
    ScanConsumeStack.push({ vueComponent, priority: priority ? priority : 0 })
    ScanConsumeStack.sort((a, b) => b.priority - a.priority)
}
function removeScanConsume(vueComponent) {
    const i = ScanConsumeStack.findIndex((currentValue)=> currentValue.vueComponent==vueComponent)
    if (i >= 0) {
        ScanConsumeStack.splice(i, 1)
    }
}
/**
 * 每个扫描组件都需要实现scanValue，返回bool 表示是否处理
 * @param {*} value
 */
function scanValue(value) {

    for(let i = 0;i<ScanConsumeStack.length;i++){
        const vueComponent = ScanConsumeStack[i].vueComponent
        if(vueComponent.scanValue instanceof Function&&!!vueComponent.scanValue(value)){
            return true
        }
    }

    return false
}


export default {
    addScanConsume,
    removeScanConsume,
    scanValue,
}
